package net.sk.china.city.domain.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import net.sk.china.city.domain.ArInventory;
import net.sk.china.city.domain.dto.donate.DonateSourceDTO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class SupermarketProductInfoVO {

    /** 商品id */
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long id;

    /** 商品首图 */
    private String indexImg;

    /** 商品名称 */
    private String productName;

    /** 积分价值 */
    private BigDecimal integratedWorth;

    /**
     * 销量
     */
    private Integer salesVolume;
    /** 商品类别id */

    /**
     * 商品类别id
     */
    private Long categoryId;

    /** 商品类别 */
    private String categoryName;

    /**
     * 类别种类
     */
    private String kind;

    /** 总库存 */
    private Integer inventory;

    /** 上架时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date releaseTime;

    /** 商品状态(0:待上架，1：上架，2：下架) */
    private String productStatus;

    //详情id
    @JsonFormat(shape = JsonFormat.Shape.STRING)
    private Long detailsId;

    /** 兑换地点id */
    private Long locationId;

    /** 兑换地点 */
    private String exchangeLocation;

    /**
     * 捐赠来源
     */
    private String sourceId;

    private List<DonateSourceDTO> donateSourceDTOS;

    /** 品牌 */
    private String brand;

    /** 风格 */
    private String style;

    /** 功能性 */
    private String functionality;

    /**
     * 保质期
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    private Date sellByDate;

    /** 服务介绍 */
    private String serviceIntroduce;

    /** 详情图片 */
    private String imgUrl;

    //库存信息
    private List<ArInventory> inventories;

    public List<String> getImgUrl() {
        List<String> imgUrlList = new ArrayList<>();
        if (imgUrl != null && imgUrl.startsWith("[") && imgUrl.endsWith("]")) {
            imgUrl = imgUrl.substring(1, imgUrl.length() - 1);
            String[] urls = imgUrl.split(",");
            for (String url : urls) {
                imgUrlList.add(url.trim().replace("\"", ""));
            }
        }
        return imgUrlList;
    }
}
